package com.toefl.speaking.handler;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.toefl.speaking.util.AppConstans;
import com.toefl.speaking.util.AppUtils;

public class RewardHandler {

	private static RewardHandler instance;

	private Reward reward;

	private String REWARD = "reward/";
	private String ISSUE="issue/";

	private RewardHandler() {

	}

	public static RewardHandler instance() {
		if (instance == null) {
			instance = new RewardHandler();
		}
		return instance;
	}

	public Reward getRewardIssue() {
		if (reward == null) {
			reward = new Reward();
		}
		return reward;
	}

	/**
	 * 发布悬赏
	 * @param reward
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public String postRewardIssue(Reward reward,int questionID) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		nameValuePairs.add(new BasicNameValuePair(AppConstans.Amount, reward.getAmount()));
		nameValuePairs.add(new BasicNameValuePair(AppConstans.LifeTime, reward.getLifeTime()));
		return AppUtils.doPost(AppConstans.INTERFACE_URL+REWARD+ISSUE+questionID, nameValuePairs);
	}

	public String postRewardAgain(Reward rewardAgain, Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		nameValuePairs.add(new BasicNameValuePair(AppConstans.Amount, rewardAgain.getAmount()));
		nameValuePairs.add(new BasicNameValuePair(AppConstans.LifeTime, rewardAgain.getLifeTime()));
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public String postRewardAmountList(Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public String postRewardAnswerList(Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public String postRewardBestHandler(Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public String postRewardList(Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public String postRewardMyList(Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public String postRewardRankingt(Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public String postRewardReply(Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public String postRewardReplyList(Context context) throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		return AppUtils.httpPost(AppConstans.INTERFACE_URL, nameValuePairs);
	}

	public class Reward {
		private String Amount;
		private String LifeTime;

		public String getAmount() {
			return Amount;
		}

		public void setAmount(String amount) {
			Amount = amount;
		}

		public String getLifeTime() {
			return LifeTime;
		}

		public void setLifeTime(String lifeTime) {
			LifeTime = lifeTime;
		}

	}

}
